package com.d0318.homework;

import java.util.ArrayList;

public class Party implements Runnable{
    int i=1;
    String num;

    public Party(){
        super();
        this.num = num;
    }
    @Override
    public void run() {
        comeIn();
    }
    public synchronized void comeIn() {
        i=i++;
        System.out.println(i+" 号员工 "+Thread.currentThread().getName()+" 进入 奖牌号码是: "+num);

        try {//可以没有，写是为了看清入场
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class PartyTest{
    public static void main(String[] args) {
        Party party;
        Thread fDoor;//前门线程
        Thread bDoor;//后门线程
        boolean isDoor=true;//判断前后门进场
        for (int i = 1; i <=30; i++) {//30个号码
            int num=(int)(Math.random()*30+1);//随机生成一个
//            ArrayList<Integer> lottery=new ArrayList<>();//定义彩票的number
//            StringBuffer sBuffer=new StringBuffer("[");
//            for (int j = 0; j < 7; j++) {
//                lottery.add((int)(Math.random()*32));
//                if (j!=7) {
//                    sBuffer.append(lottery.get(j)+",");
//                }else {
//                    sBuffer.append(lottery.get(j));
//                }
//            }
//            sBuffer.append("]");
            party=new Party();
            fDoor=new Thread(party,"前门");
            bDoor=new Thread(party,"后门");
            if (isDoor) {
                fDoor.start();
            } else {
                bDoor.start();
            }
            isDoor=!isDoor;
        }
    }
}
